//
//  WKFoundWalletViewController.m
//  ourToken
//
//  Created by wakeup on 2018/6/6.
//  Copyright © 2018年 ourtoken. All rights reserved.
//

#import "WKFoundWalletViewController.h"
#import "WKBaseHeader.h"

@interface WKFoundWalletViewController ()<UICollectionViewDelegate, UICollectionViewDataSource>

@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) NSArray *dataArray;//数据源

@end

@implementation WKFoundWalletViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavigationView];
    [self layoutUI];
    self.view.backgroundColor = [UIColor whiteColor];
    [self.collectionView registerNib:[UINib nibWithNibName:@"WKFoundWalletCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"FoundWallet"];
    
    self.dataArray = @[
                       @[@"比特币",@"以太币"],
                       @[@"b",@"e"]
                       ];
}

- (void)setNavigationView {
    [super setNavigationView];
    if(self.foundType==1){
    self.navigationView.topTitleLabel.text = @"创建钱包";
    }
    else{
    self.navigationView.topTitleLabel.text = @"导入钱包";
    }
}

- (void)layoutUI {
    [self.view addSubview:self.collectionView];
}

#pragma mark - UICollectionViewDelegate
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 2;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    WKFoundWalletCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"FoundWallet" forIndexPath:indexPath];
    cell.coinImageView.image = [UIImage imageNamed:self.dataArray[1][indexPath.row]];
    cell.coinType.text = self.dataArray[0][indexPath.row];
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    if (self.foundType == 1) {
        WKFoundWalletViewController1 *foundWallet1 = [[WKFoundWalletViewController1 alloc] init];
        if (indexPath.item == 0) {
            foundWallet1.coinType = @"BTC";
        }
        else {
            foundWallet1.coinType = @"ETH";
        }
        [self.navigationController pushViewController:foundWallet1 animated:YES];
    }
    else {
        WKLoadWalletViewController *loadWallet = [[WKLoadWalletViewController alloc] init];
        if (indexPath.item == 0) {
            loadWallet.coinType = @"BTC";
        }
        else {
            loadWallet.coinType = @"ETH";
        }
        [self.navigationController pushViewController:loadWallet animated:YES];
    }
}

#pragma mark - 懒加载
- (UICollectionView *)collectionView {
    if (_collectionView == nil) {
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.sectionInset = UIEdgeInsetsMake(15, 15, 15, 15);
        flowLayout.itemSize = CGSizeMake(135*AppManager.scale, 150*AppManager.scale);
        flowLayout.minimumLineSpacing = 10;
        flowLayout.minimumInteritemSpacing = 10;
        
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, AppManager.navigationHeight, AppManager.width, AppManager.height-AppManager.navigationHeight) collectionViewLayout:flowLayout];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.backgroundColor = AppManager.tableBackColor;
    }
    return _collectionView;
}

@end
